<?php

use yii\db\Migration;

class m170701_094723_add_new_attendance_module_tables extends Migration
{
    public function safeUp()
    {
         $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }
        //1.创建新考勤表 一个工作日两次上下班 两次旷工，按次数统计
        $this->createTable('ts_new_attendance', [
            'id' => $this->primaryKey(),
            'mobile' => $this->string(11)->notNull()->comment('手机号码'),
            'work_date' => $this->date()->notNull()->comment('工作日期'),
            'attendance' => $this->smallInteger()->notNull()->defaultValue(1)->comment('考勤状态'),
            'am_pm'=>$this->smallInteger()->defaultValue(1)->comment('上午或下午'),
            'num'=>$this->smallInteger()->defaultValue(0)->comment('迟到早退次数'),
            'start_at'=>$this->Integer()->comment('考勤开始时间'),
            'end_at'=>$this->Integer()->comment('考勤结束时间'),
            'state'=>$this->smallInteger()->comment('状态'),
            ], $tableOptions);
        $this->createIndex('mobile','ts_new_attendance','mobile');
    }
    
    public function safeDown()
    {
        echo "m170701_094723_add_new_attendance_module_tables cannot be reverted.\n";
        $this->dropTable('ts_new_attendance');
    }
}
